﻿using System.Collections.Generic;
using System.Linq;
using InvestmentIntelligence.DbModel.Models;

namespace InvestmentIntelligence.Data.Repository.EFImplementation
{
    public class OriginalPositionValidationDataRepository : IIPRepository<OriginalPositionValidationData>, IOriginalPositionValidationDataRepository
    {
        public void Remove(IEnumerable<OriginalPositionValidationData> positionIds)
        {
            RunUnitOfWork(data =>
            {
                foreach (var item in positionIds)
                {
                    var validationData = data.OriginalPositionValidationData.SingleOrDefault(x => x.Date == item.Date && x.FundBookEntityId == item.FundBookEntityId && x.SecurityId == item.SecurityId);
                    if (validationData != null)
                    {

                        data.OriginalPositionValidationData.Remove(validationData);
                    }
                }
                data.SaveChanges();
                return default(OriginalPositionValidationData);
            });
        }
    }
}